<template>
  <div style="height: 100%">
    <div style="height: 90%">
      <template v-for="item in dict.type.play_type">
        <el-row>
          <el-row :gutter="10">
            <el-col :xs="3" :sm="3" :md="3" :lg="3" :xl="3">
              <dict-tag :options="dict.type.play_type" :value="item.value"></dict-tag>
            </el-col>
            <el-col :xs="4" :sm="6" :md="4" :lg="6" :xl="6" v-for="oddsRule in oddsRules[item.value]">
              <el-divider direction="vertical"></el-divider>
              <el-tooltip class="item" effect="light"
                          placement="right"
              >
                <div slot="content">
                  <el-row :gutter="10">
                    <el-col :span="12">
                        <el-statistic title="赔率" :precision="2" :value="oddsRule.odds"/>
                    </el-col>
                    <el-col :span="12">
                        <el-statistic title="退水比例" :precision="2" :value="oddsRule.waterRate "/>
                    </el-col>


                  </el-row>


                </div>
                <el-radio v-model="checkList[item.value]" :label="oddsRule.id" border>{{ oddsRule.name }}</el-radio>
              </el-tooltip>
            </el-col>
          </el-row>
        </el-row>
        <el-divider></el-divider>
      </template>
    </div>
    <div style="height: 10%">
      <el-button type="primary" @click="submit" :loading="loading">保存</el-button>
    </div>
  </div>
</template>
<script>
import { custOddsList, settingCustOdds } from '@/api/financial/rule'

export default {
  dicts: ['play_type'],
  name: 'CustOddsSetting',
  props: {
    custId: {
      type: Number,
      default: null
    },
    custType: {
      type: String,
      default: '1'
    },
    bankerId: {
      type: Number,
      default: null
    },
    value: [Number, String, Array]
  },
  data() {
    return {
      loading: false,
      oddsList: [
        { 'key': 'TM', label: '特码', value: 1, name: '特码标准赔率' },
        { 'key': 'MZ', label: '平码', value: 1, name: '平码标准赔率' }
      ],
      oddsRules: {},
      checkList: {}

    }
  },
  created() {
    this.getSettings()
  },
  computed: {},
  methods: {
    getSettings() {
      var query = {
        custId: this.custId,
        bankerId: this.bankerId,
        custType: this.custType
      }
      custOddsList(query).then(res => {
        this.oddsRules = res.data.list
        this.checkList = res.data.check
      })
    },
    submit() {
      this.loading = true
      var data = {
        bankerId: this.bankerId,
        custId: this.custId,
        data: this.checkList
      }
      this.$modal.confirm('请检查赔率是否设置无误？').then(function() {

        return settingCustOdds(data)

      }).then(() => {
        this.loading = false
        this.$modal.msgSuccess('设置成功')
      }).catch(e => {
        console.log(e)
        this.$modal.msgError('设置失败')
        this.loading = false
      })

    }
  },
  filters: {}
}
</script>
